"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.removeSvgs = void 0;
const templates_1 = require("./templates");
const tools_1 = require("./tools");
const fs = require("fs");
const path = require("path");
function removeSvgs(options) {
    options.outputValue = options.outputValue || options.inputValue;
    const { inputValue = "", remove } = options;
    if (!remove || typeof remove !== "string") {
        throw new Error("remove should be a string");
    }
    const inputPath = path.join(process.cwd(), ...inputValue.split("/").filter(Boolean));
    if (!fs.statSync(inputPath).isFile() && !inputValue.endsWith(".js")) {
        throw new Error("input should be a .js file");
    }
    const { svgId, svgList: oldSvgList } = (0, tools_1.getIconfontContent)(inputPath);
    const removeMap = remove
        .split(",")
        .filter(Boolean)
        .reduce((p, id) => {
        p[id] = true;
        return p;
    }, {});
    outputFile(svgId, oldSvgList.filter((svg) => !removeMap[svg.name]), options);
}
exports.removeSvgs = removeSvgs;
// 输出iconfont.js文件
function outputFile(svgId, svgList, options) {
    const { outputValue } = options;
    const outputPath = (0, tools_1.getOutputPath)(outputValue, "iconfont.js", ".js");
    const content = (0, templates_1.generateIconfontContent)(svgList.map(templates_1.generateSymbolContnt).join(""), svgId);
    fs.writeFileSync(outputPath, content);
    const html = (0, templates_1.generateHtmlContent)(svgList.map((item) => item.name));
    const htmlPath = path.join(path.parse(outputPath).dir, "index.html");
    fs.writeFileSync(htmlPath, html);
}
